# name : LOCF using retain, template
# key : locf.retain.template
# contributor: Shuguang Sun
# --
proc sort data=lab;
  by usubjid lbtestcd avisitn;
run;

data locf;
  length dtype \$15;
  retain retain;
  set lab;
  by usubjid lbtestcd avisitn;
  if first.lbtestcd then retain=.;
  if aval ne . then retain=aval;
   if aval=. then do;
    avallocf=retain;
    dtype='LOCF';
  end;
  else avallocf=aval;
run;